//
//  def_declaration.h
//  compilation
//
//  Created by Kevin Le perf on 17/01/12.
//  Copyright (c) 2012 e2co technologie. All rights reserved.
//

#ifndef compilation_def_declaration_h
#define compilation_def_declaration_h

/*
 declaration
 : type_name declarator_list ';' {printf("declaration\n");
 
 enum type _type_name_here = type_name_stack_head();
 printf("declaration de variable "); type_print(_type_name_here);
 type_name_stack_pop();}
 ; 
 */

struct def_declaration{
	void * parent;
	int type;
	enum type type_name;
	struct def_declarator_list * declarator_list;
	
	struct symbol * _symbols[32];
	int _count;
};

struct def_declaration * declaration_create(void * parent){
	struct def_declaration * d = malloc(sizeof(*d));
	d->type = 0;
	d->parent = parent;
	d->_count = 0;
	return d;
}

void declaration_add(struct def_declaration * d, struct symbol *s){
	d->_symbols[d->_count] = s;
	d->_count++;
}

void declaration_print(struct def_declaration * d){
	if(d->type == 1){
		type_print(d->type_name);
		printf(" ");
		declarator_list_print(d->declarator_list);
		printf(";\n");
	}else if(d->type == 2){
		int i;
		for(i=0;i<d->_count;i++){
			symbol_print_type(d->_symbols[i]);
			printf(" ");
			symbol_print_name(d->_symbols[i]);
			printf(" ");
			symbol_print_def(d->_symbols[i]);
			printf(";\n");
		}
	}
}
#endif
